package ray.mgocc.title;

import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;

public abstract class Requirement implements Comparable{
    abstract public String getName();
    abstract public double getRatio();
    public boolean check(){
        return 1 <= getRatio();
    }
    public int percent(){
        return (int)(getRatio()*100);
    }
    public String toString(){
        return getName()+"["+percent()+"%]";//+check();
    }
    String format(double value){
        final int SCALE = 2;
        final int ZERO_ORIGIN = 1;
        String original = Double.toString(value);
        String str = "";
        int index = 0;
        while(-1 == str.indexOf('.') ||
              str.length() < str.indexOf('.')+ZERO_ORIGIN+SCALE){
            if(str.length() < original.length()){
                str += original.charAt(index);
            }else{
                if(-1==str.indexOf('.')){
                    str += ".";
                }else{
                    str += "0";
                }
            }
            index++;
        }
        return str;
    }
    public int compareTo(Object that){
        int diff = -1;
        if(that instanceof Requirement){
            diff = this.percent() - ((Requirement)that).percent();
        }
        return diff;
    }
}
